#include "Matrix.h"
#include "Math.h"

	Matrix::Matrix()
	{
	}
	Matrix::Matrix(float v)
	{
		for(int y = 0;y < 4;++y)
		{
			for(int x = 0;x < 4;++x)
			{
				M[x][y] = v;
			}
		}
	}
	Matrix::Matrix(float m[4][4])
	{
		for(int y = 0;y < 4;++y)
		{
			for(int x = 0;x < 4;++x)
			{
			M[x][y] = m[x][y];
			}
		}
	}
	Matrix Matrix::operator* (Matrix matrix)
	{
		Matrix newMatrix;
		for(int y = 0;y < 4;++y)
		{
			for(int x = 0;x < 4;++x)
			{
				float sum = 0;
				for(int i = 0;i < 4;++i)
				{
					sum += M[i][y]*matrix.M[x][i];
				}
				newMatrix.M[x][y] = sum;
			}
		}
		return newMatrix;
	}
	
	Matrix Matrix::CreateTranslation(Vector3 t)
	{
		float m[4][4] = {
			{1,0,0,t.X},
			{0,1,0,t.Y},
			{0,0,1,t.Z},
			{0,0,0,1}};
		return Matrix(m);
	}
	Matrix Matrix::CreateScale(float s)
	{
		float m[4][4] = {
			{s,0,0,0},
			{0,s,0,0},
			{0,0,s,0},
			{0,0,0,1}};
		return Matrix(m);
	}
	Matrix Matrix::CreateScale(Vector3 s)
	{
		float m[4][4] = {
			{s.X,0,0,0},
			{0,s.Y,0,0},
			{0,0,s.Z,0},
			{0,0,0,1}};
		return Matrix(m);
	}
	Matrix Matrix::CreateRotationX(float v)
	{
		float m[4][4] = {
			{1,0,0,0},
			{0,cos(v),-sin(v),0},
			{0,sin(v),cos(v),0},
			{0,0,0,1}};
		return Matrix(m);
	}
	Matrix Matrix::CreateRotationY(float v)
	{
		float m[4][4] = {
			{cos(v),0,sin(v),0},
			{0,1,0,0},
			{-sin(v),0,cos(v),0},
			{0,0,0,1}};
		return Matrix(m);
	}
	Matrix Matrix::CreateRotationZ(float v)
	{
		float m[4][4] = {
			{cos(v),-sin(v),0,0},
			{sin(v),cos(v),0,0},
			{0,0,1,0},
			{0,0,0,1}};
		return Matrix(m);
	}

	Matrix Matrix::Identity = Matrix(1);